package com.supermap.business.agriculture;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dubbo.api.agrinfo.entity.Agrpraise;
import com.supermap.dubbo.api.agrinfo.AgrpraiseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lxs
 * @Title:农情点赞接口层
 * @Description:
 * @date 2018/3/8  16:51
 */
@Controller
@RequestMapping("AgrpraiseController")
public class AgrpraiseController {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(AgrpraiseController.class);

    @Reference
    private AgrpraiseService agrpraiseService;

    /**
     * 根据农情ID得到对应的农情点赞数
     * @param request
     * @return
     */
    @RequestMapping("/getAgrpraiseCount")
    @ResponseBody
    public int getAgrpraiseCount(HttpServletRequest request){
       String agrInfoId= request.getParameter("agrInfoId");
        return agrpraiseService.getAgrpraiseCount(Integer.valueOf(agrInfoId));
    }
    /**
     *判断该用户是否对该农情点过赞
     */
    @RequestMapping("/getPraise")
    @ResponseBody
    public boolean getPraise(HttpServletRequest request){
        String userId= request.getParameter("userId");
        String agrInfoId= request.getParameter("agrInfoId");
        return agrpraiseService.getPraise(Integer.valueOf(userId),Integer.valueOf(agrInfoId));
    }

    /**
     *点赞
     * @param request
     * @param agrpraise
     * @return
     */
    @RequestMapping("/addAgrpraise")
    @ResponseBody
    public boolean addAgrpraise(HttpServletRequest request, Agrpraise agrpraise){
        return agrpraiseService.addAgrpraise(agrpraise);
    }

}
